package com.vehicle.service.Impl;

import cn.hutool.core.collection.CollectionUtil;
import com.vehicle.domains.entity.SysUserRoleEntity;
import com.vehicle.mapper.SysUserRoleMapper;
import com.vehicle.service.SysUserRoleService;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class SysUserRoleServiceImpl implements SysUserRoleService {

    @Resource
    private SysUserRoleMapper sysUserRoleMapper;


    @Override
    @Transactional(rollbackFor = Exception.class)
    public void addUserRoles(Long userId, List<SysUserRoleEntity> list) {
        sysUserRoleMapper.deleteRolesByUserId(userId);
        if (CollectionUtil.isNotEmpty(list)) {
            sysUserRoleMapper.batchInsertUserRoles(list);
        }
    }
}
